{-  Copyright (C) 2014 Mark W Pearse  
  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.
-}

module Main where

import E_Data
import E_API
import E_rawAPI

_BufSize = 50
_BufOffset = 0x01000000

-- load and run the "hello world" program on a single core, then show the resulting message
helloOneCore memptr defptr (row,col) = do
       putStr ("core" ++ show (row,col) ++ ": " )
       e_open defptr row col 1 1
       e_reset_group defptr
       eLoad "e_hello_world.srec" defptr 0 0 e_true  -- e_true -> run after loading
       usleep 10000
       message <- ememReadString memptr 0 _BufSize 
       putStrLn message
       e_close defptr

-- set up epiphany environment and run the "hello world" program on all available cores
main = withEpiphany "/opt/adapteva/esdk/bsps/current/platform.hdf" (
           withBuffer _BufOffset _BufSize (\memptr -> 
               withGroupRef (\defptr -> do
                   helloOneCore memptr defptr (0,0)
                   mapM_ (helloOneCore memptr defptr) (allcores platformInfo)
               )
           )       
       ) 

